package com.pdh.file.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;

/**
 * @Author: 彭_德华
 * @Date: 2021-10-14 14:57
 * 覆盖默认的配置信息
 */
@Configuration
@EnableOpenApi
public class Swagger3Config {

    @Value("${config.swagger3.flag}")
    private boolean flag;

    @Bean
    public Docket docket(Environment environment){
        return new Docket(DocumentationType.OAS_30) // 指定3.0版本
                .groupName("文件上传")
                .apiInfo(apiInfo())
                .enable(flag)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.pdh.file.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){

        return new ApiInfo("基于SpringBoot上传文件",
                "基于SpringBoot，实现上传文件到本地电脑和上传文件到云服务器（以七牛云服务器为例）",
                "v1.0",
                "https://blog.csdn.net/yeahPeng11",
                new Contact("彭德华","https://blog.csdn.net/yeahPeng11","pdhcool@163.com"),
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
